package servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author： pang-yun
 * @date： 2021-11-26 11:47
 * 功能目的 ：用于 测试 servletContext
 */

public class ContextTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();
        //获取 配置的上下文参数
        System.out.println(servletContext.getInitParameter("user"));
        // 获取  工程路径
        System.out.println(servletContext.getContextPath());
        // 获取真实 路径
        System.out.println(servletContext.getRealPath("/"));
        System.out.println("测试 其servletContext 共享参数 "+getServletContext().getAttribute("testParam"));
    }
}
